package java8.time;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author dan shouyang
 */
public class DateUtil {

    public static void main(String[] args) throws  Exception{
        String str = "2015-01-05 17:00:01:111111";

        ZoneId australia = ZoneId.of("Australia/Sydney");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSSSSS");
        LocalDateTime localtDateAndTime = LocalDateTime.parse(str, formatter);
        System.out.println("localtDateAndTime : " + localtDateAndTime);
        ZonedDateTime dateAndTimeInSydney = ZonedDateTime.of(localtDateAndTime, australia );
        System.out.println("Current date and time in a particular timezone : " + dateAndTimeInSydney);

        ZonedDateTime utcDate = dateAndTimeInSydney.withZoneSameInstant(ZoneOffset.UTC);
        System.out.println("Current date and time in UTC : " + utcDate);
        System.out.println("Current date and time in UTC : " + utcDate.toString());

//        LocalDateTime localtDateAndTime1 = LocalDateTime.parse(str);
//        System.out.println("localtDateAndTime1 : " + localtDateAndTime1);
    }
}
